import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Divisas extends JFrame implements ActionListener{
	
	private double num1 = 0, num2 = 0;
	private JTextField num1Text;
	private JTextField num2Text;
	private JTextField cambio;
	private JComboBox<String> origen;
	private JComboBox<String> destino;
	private JButton boton;
	private JLabel cambioText;
	
	public Divisas () {
		this.setLayout(null);
		String monedas [] = {"Euro", "USD"};
		
		origen = new JComboBox<String>(monedas);		
		origen.setBounds(30, 50, 100, 30);
		add(origen);
		
		destino = new JComboBox<String>(monedas);
		destino.setBounds(250, 50, 100, 30);
		add(destino);
		
		num1Text = new JTextField();
		num1Text.setBounds(20, 100, 120, 30);
		add(num1Text);
		
		num2Text = new JTextField();
		num2Text.setBounds(240, 100, 120, 30);
		add(num2Text);
		
		cambio = new JTextField();
		cambio.setBounds(150, 50, 80, 30);
		add(cambio);
		
		cambioText = new JLabel("  -- Cambio --");
		cambioText.setBounds(150, 20, 100, 30);
		add(cambioText);
		
		boton = new JButton("Cambiar");
		boton.setFont(new Font("Dialog", 1, 10));
		boton.setBounds(150, 100, 80, 30);
		boton.addActionListener(this);
		add(boton);
	}	
	
	public void actionPerformed (ActionEvent ae) {
		if (ae.getSource() == boton) {
			try {
				if (origen.getSelectedItem().equals("Euro") && destino.getSelectedItem().equals("USD")) {
					num2Text.setText(String.valueOf((float)(Double.parseDouble(num1Text.getText()) * Double.parseDouble(cambio.getText()))));
				}
				else {
					if (origen.getSelectedItem().equals("USD") && destino.getSelectedItem().equals("Euro")) {
						num2Text.setText(String.valueOf((float)(Double.parseDouble(num1Text.getText()) * Double.parseDouble(cambio.getText()))));
					}
					else {
						num2Text.setText(num1Text.getText());
					}
				}
			}
			catch (Exception e) {
				JOptionPane.showMessageDialog(this, "ERROR MOTHERFUCKER");
			}
		}
	}	
	
	public static void main(String[] args) {
		Divisas d1 = new Divisas();
		d1.setBounds(300, 300, 400, 250);
		d1.setVisible(true);
	}
}
